﻿// Decompiled with JetBrains decompiler
// Type: MCM.LightInject.LifetimeHelper
// Assembly: MCMv5, Version=5.10.2.0, Culture=neutral, PublicKeyToken=null
// MVID: 7AB326B9-B2B4-41C2-9177-68E944071101
// Assembly location: D:\steam\steamapps\workshop\content\261550\2859238197\bin\Win64_Shipping_Client\MCMv5.dll

using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Reflection;

#nullable disable
namespace MCM.LightInject
{
  [ExcludeFromCodeCoverage]
  internal static class LifetimeHelper
  {
    public static readonly MethodInfo GetInstanceMethod;
    public static readonly MethodInfo GetCurrentScopeMethod;
    private static readonly ThreadSafeDictionary<Type, MethodInfo> NonClosingGetInstanceMethods = new ThreadSafeDictionary<Type, MethodInfo>();

    static LifetimeHelper()
    {
      LifetimeHelper.GetInstanceMethod = typeof (ILifetime).GetTypeInfo().GetDeclaredMethod("GetInstance");
      LifetimeHelper.GetCurrentScopeMethod = typeof (IScopeManager).GetTypeInfo().GetDeclaredProperty("CurrentScope").GetMethod;
    }

    public static MethodInfo GetNonClosingGetInstanceMethod(Type lifetimeType)
    {
      // ISSUE: reference to a compiler-generated field
      // ISSUE: reference to a compiler-generated field
      return LifetimeHelper.NonClosingGetInstanceMethods.GetOrAdd(lifetimeType, LifetimeHelper.\u003C\u003EO.\u003C0\u003E__ResolveNonClosingGetInstanceMethod ?? (LifetimeHelper.\u003C\u003EO.\u003C0\u003E__ResolveNonClosingGetInstanceMethod = new Func<Type, MethodInfo>(LifetimeHelper.ResolveNonClosingGetInstanceMethod)));
    }

    private static MethodInfo ResolveNonClosingGetInstanceMethod(Type lifetimeType)
    {
      Type[] parameterTypes = new Type[3]
      {
        typeof (GetInstanceDelegate),
        typeof (Scope),
        typeof (object[])
      };
      return lifetimeType.GetTypeInfo().DeclaredMethods.SingleOrDefault<MethodInfo>((Func<MethodInfo, bool>) (m => ((IEnumerable<ParameterInfo>) m.GetParameters()).Select<ParameterInfo, Type>((Func<ParameterInfo, Type>) (p => p.ParameterType)).SequenceEqual<Type>((IEnumerable<Type>) parameterTypes)));
    }
  }
}
